package com.wgzx.modbus.entity.request;

import com.wgzx.modbus.entity.ModbusReq;

import static com.wgzx.modbus.constant.FunctionCode.READ_DISCRETE_INPUTS;
import static com.wgzx.modbus.util.ModbusUtil.validateRange;

/**
 * 读离散量输入 <br/>
 * 功能码：0x02 <br/>
 * 起始地址：2个字节0x0000至0xFFFF <br/>
 * 输入数量：2个字节0x01至0x07D0 <br/>
 *
 * @author gexin
 */
public class ReadDiscreteInputsRequest extends ModbusReq {

    public ReadDiscreteInputsRequest(int startingAddress, int quantityOfDiscrete) {
        super(READ_DISCRETE_INPUTS, startingAddress, quantityOfDiscrete);
        validateRange(startingAddress, "startingAddress", 0x00, 0xFFFF);
        validateRange(quantityOfDiscrete, "quantityOfCoils", 0x01, 0x07D0);
    }

    @Override
    public String toString() {
        return "ReadDiscreteInputsRequest{" + "startingAddress=" + address + ", quantityOfCoils=" + value + '}';
    }
}
